import os

from langchain_community.chat_models import ChatOpenAI

from quick_learn.chat_prompt import ChatPromptHelper


class ChatOpenAIHelper(object):
    def __init__(self):
        self.llmClient = ChatOpenAI(
            temperature=0.5,
            model_name='gpt-3.5-turbo',
            base_url='https://api.chatanywhere.tech/v1',
            openai_api_key=os.environ.get('OPENAI_API_KEY'))
        self.chatPrompt = ChatPromptHelper()

    # 请问城市有什么好吃的
    # param city 城市名称
    # return 返回回答串
    def ask_city_goods(self, city: str) -> str:
        prompt = self.chatPrompt.get_template_for_goods()
        # 构建链
        llmChains = prompt | self.llmClient
        response = llmChains.invoke({"city": city,})

        print(response, type(response))

    def ask_test(self):
        # template = """
        # 你是一个旅游销售员，你不仅要告诉用户正确的答案，还要用诗一样的语言来描述这个答案！
        # 请告诉我{country}的首都是那座城市？
        # """
        #
        # prompt3 = PromptTemplate(template=template, input_variables=["country"])
        prompt3 = self.chatPrompt.get_template_for_tourism()

        chain3 = prompt3 | self.llmClient

        chain3.invoke({"country": "英国", })
    # 自定义提示模版

